package com.ruoyi.contact.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contact.domain.ContactLevel;
import com.ruoyi.contact.service.IContactLevelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ShiroUtils;

/**
 * 联系人等级Controller
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@Controller
@RequestMapping("/contact/level")
public class ContactLevelController extends BaseController
{
    private String prefix = "contact/level";

    @Autowired
    private IContactLevelService contactLevelService;

    @RequiresPermissions("contact:level:view")
    @GetMapping()
    public String level()
    {
        return prefix + "/level";
    }

    /**
     * 查询联系人等级列表
     */
    @RequiresPermissions("contact:level:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContactLevel contactLevel)
    {
        startPage();
        List<ContactLevel> list = contactLevelService.selectContactLevelList(contactLevel);
        return getDataTable(list);
    }

    /**
     * 导出联系人等级列表
     */
    @RequiresPermissions("contact:level:export")
    @Log(title = "联系人等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ContactLevel contactLevel)
    {
        List<ContactLevel> list = contactLevelService.selectContactLevelList(contactLevel);
        ExcelUtil<ContactLevel> util = new ExcelUtil<ContactLevel>(ContactLevel.class);
        return util.exportExcel(list, "联系人等级数据");
    }

    /**
     * 新增联系人等级
     */
    @RequiresPermissions("contact:level:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存联系人等级
     */
    @RequiresPermissions("contact:level:add")
    @Log(title = "联系人等级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContactLevel contactLevel)
    {
        contactLevel.setUserId(ShiroUtils.getUserId());
        return toAjax(contactLevelService.insertContactLevel(contactLevel));
    }

    /**
     * 修改联系人等级
     */
    @RequiresPermissions("contact:level:edit")
    @GetMapping("/edit/{levelId}")
    public String edit(@PathVariable("levelId") Long levelId, ModelMap mmap)
    {
        ContactLevel contactLevel = contactLevelService.selectContactLevelByLevelId(levelId);
        mmap.put("contactLevel", contactLevel);
        return prefix + "/edit";
    }

    /**
     * 修改保存联系人等级
     */
    @RequiresPermissions("contact:level:edit")
    @Log(title = "联系人等级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContactLevel contactLevel)
    {
        contactLevel.setUserId(ShiroUtils.getUserId());
        return toAjax(contactLevelService.updateContactLevel(contactLevel));
    }

    /**
     * 删除联系人等级
     */
    @RequiresPermissions("contact:level:remove")
    @Log(title = "联系人等级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contactLevelService.deleteContactLevelByLevelIds(ids));
    }
}
